/**
 * 员工月度绩效信息
 */
app.controller('btnCtrl', ['$scope', '$http', BtnController]);
function BtnController($scope, $http){
    console.log('------$scope.menuId1-----', $scope.menuId);
    console.log('------$scope.buttonArr1-----', $scope.buttonArr);


    $scope.bindBtn = function(event) {
        var datas = $scope.getSelectedRows();
        switch(event){
            case 'LAYTABLE_EXPORT_DATA':
            {
                $scope.doExport('/api/inter/tbUserMonthPerformance/export');
                break;
            }
            case 'event-to-edit'://编辑
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else if(datas.length > 1) {
                    layer.alert('只能选中一行数据');
                } else {
                    window.top.add_tab('员工月度绩效信息 - 编辑', '/web/base/tbUserMonthPerformance/toEdit?id=' + datas[0].id);
                }
                break;
            }
            case 'event-to-push'://生成工资条
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    var ids = '';
                    for(var i=0;i<datas.length;i++){
                        if(ids==''){
                            ids = datas[i].id;
                        }else {
                            ids = ids + ',' +datas[i].id;
                        }
                    }
                    layer.msg('处理中', {
                        icon: 16,shade: 0.01
                    });
                    $http.post('/api/inter/tbUserMonthPerformance/addUserPaySlip', {}, {params: {ids: ids}})
                        .success(function (res) {
                            layer.closeAll();
                            layer.alert(res.msg);
                            setTimeout(function(){
                                //layer.closeAll();
                                location.reload();
                            }, 3000);
                        })
                        .error(function(result){
                            layer.close();
                            layer.msg("操作失败，请稍后再试！", {icon: 2});
                        });

                }
                break;
            }
            case 'event-to-importAttendance'://考勤导入
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    var ids = '';
                    for(var i=0;i<datas.length;i++){
                        if(ids==''){
                            ids = datas[i].id;
                        }else {
                            ids = ids + ',' +datas[i].id;
                        }
                    }
                    layer.msg('处理中', {
                        icon: 16,shade: 0.01
                    });

                    $http.post('/api/inter/tbUserMonthPerformance/updateUserAttendanceId', {}, {params: {ids: ids}})
                        .success(function (res) {
                            layer.closeAll();
                            layer.alert(res.msg);
                            setTimeout(function(){
                                //layer.closeAll();
                                location.reload();
                            }, 3000);
                        })
                        .error(function(result){
                            layer.close();
                            layer.msg("操作失败，请稍后再试！", {icon: 2});
                        });


                }
                break;
            }
            case 'event-to-del'://删除
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    var ids = '';
                    for(var i=0;i<datas.length;i++){
                        if(ids==''){
                            ids = datas[i].id;
                        }else {
                            ids = ids + ',' +datas[i].id;
                        }
                    }
                    layer.confirm('确定要删除吗？', {icon: 3}, function () {
                        layer.msg('处理中', {
                            icon: 16,shade: 0.01
                        });
                        $http.post('/api/inter/tbUserMonthPerformance/toDel', {}, {params: {ids: ids}})
                            .success(function (res) {
                                layer.closeAll();
                                layer.alert(res.msg);
                                setTimeout(function(){
                                    //layer.closeAll();
                                    location.reload();
                                }, 3000);
                            })
                            .error(function(result){
                                layer.close();
                                layer.msg("操作失败，请稍后再试！", {icon: 2});
                            });

                    }, function () {});
                }
                break;
            }

            case 'event-to-updateAttendance'://修改考勤状态
            {
                if(datas.length == 0) {
                    layer.alert('尚未选中数据');
                } else {
                    var _list = [];
                    for(var i=0;i<datas.length;i++){
                        _list[i]=datas[i].id;
                    }
                    layer.msg('处理中', {
                        icon: 16,shade: 0.01
                    });
                    $.ajax({
                        url: '/api/inter/tbUserMonthPerformance/updateAttendanceStatus',
                        data: "list="+_list,
                        type: 'POST',
                        async: true,
                        success: function (res) {
                            layer.closeAll();
                            layer.alert(res.msg);
                            setTimeout(function(){
                                //layer.closeAll();
                                location.reload();
                            }, 3000);

                        },
                        error: function () {
                            layer.close();
                            layer.msg("操作失败，请稍后再试！", {icon: 2});
                        }
                    });
                }
                break;
            }

        };
    }
}


//表格双击
app.controller('dbClickCtrl', ['$scope', '$http', DbClickController]);
function DbClickController($scope, $http){
    $scope.doubleClick = function(data) {
        console.log('------data-----', data);
        window.top.add_tab('员工月度绩效信息 - 详情','/web/base/tbUserMonthPerformance/toDetail?id=' + data.id);
    }
}

